package East_newsK;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.List;

public class East_news {
    public static void main(String[] args) throws Exception{
        String url ="http://finance.eastmoney.com/a/cgnjj.html";
        getTargetgUrl(url);
    }


    public  static void getTargetgUrl(String url) throws Exception {
        System.setProperty("webdriver.chrome.driver", "E:\\Java\\工具包\\Chromedriver\\chromedriver.exe");
        int i = 1;
        WebDriver driver = new ChromeDriver();
        driver.get(url);
        while(i<=1){
            System.out.printf("本次解析%d页",i);
            //获取本业的目标链接
            List<WebElement> list =driver.findElements(By.cssSelector("#newsListContent li .title a"));
            for (WebElement webElement : list) {
                String href = webElement.getAttribute("href");
                System.out.println(href);
                System.out.println("开始解析");
                News_analysis.news_analysis(href,"#ContentBody p");
            }
            //进入下一页
            List<WebElement> listb = driver.findElements(By.cssSelector("#pagerNoDiv .page-btn"));
            if (listb.size() >= 2){
                WebElement webElement  = listb.get(1);
                System.out.println("开始进入下一页");
                driver.get(webElement.getAttribute("href"));
            }
            else{
                WebElement webElement = listb.get(0);
                System.out.println("开始进入下一页");
                driver.get(webElement.getAttribute("href"));
            }
            i++;
        }
                System.out.println("完成");
    }}